package com.simit.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class YuanShenAdvice {
    @Pointcut("execution(com.simit.pojo.YuanShen com.simit.service.YuanShenService.selectByName(String))")
    private void pt() {}

    @Pointcut("execution(* com.simit.service.*Service.select*(..))")
    private void ptx() {}

//    @Before("ptx()")
    public void before() {
        System.out.println("before ...");
    }

//    @After("ptx()")
    public void after() {
        System.out.println("after ...");
    }

//    @Around("ptx()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Signature signature = pjp.getSignature();
        String type = signature.getDeclaringTypeName();
        String name = signature.getName();

        long start = System.currentTimeMillis();
        for(int i = 0; i < 9999; i++) {
            pjp.proceed();
        }
        Object ret = pjp.proceed();
        System.out.println("after ...");
        long end = System.currentTimeMillis();
        System.out.println("万次执行时间：" + type + "." + name + "---->" + (end - start) + "ms");
        return ret;
    }

//    @AfterReturning
//    @AfterThrowing
}
